﻿#region zh-CHS 2006 - 2007 DemoSoft 团队 | en 2006 - 2007 DemoSoft Team

//     NOTES
// ---------------
//
// This file is a part of the MMOSE(Massively Multiplayer Online Server Engine) for .NET.
//
//                              2006-2007 DemoSoft Team
//
//
// First Version : by H.Q.Cai - mailto:caihuanqing@hotmail.com

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as published
 *   by the Free Software Foundation; either version 2.1 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

#region zh-CHS 包含名字空间 | en Include namespace
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using Demo.Mmose.Core.Map;
using Demo.Mmose.Core.World;
using Demo.Mmose.Core.Util;
using System.Threading;
#endregion

namespace Demo.Mmose.Core.Common
{
    /// <summary>
    /// 
    /// </summary>
    public abstract class GameEntity
    {
    }

    /// <summary>
    /// 
    /// </summary>
    public abstract class GameEntity1 : ISerial, ILocation, IPoint4D, IComparable, IComparable<GameEntity1>
    {
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private Serial m_Serial = 0;
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public Serial Serial
        {
            get { return m_Serial; }
            set { m_Serial = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        public float X
        {
            get { return m_Point4D.X; }
            set { m_Point4D.X = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        public float Y
        {
            get { return m_Point4D.Y; }
            set { m_Point4D.Y = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        public float Z
        {
            get { return m_Point4D.Z; }
            set { m_Point4D.Z = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        public float O
        {
            get { return m_Point4D.O; }
            set { m_Point4D.O = value; }
        }

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private Point4D m_Point4D = Point4D.Zero;
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public Point3D Location
        {
            get { return (Point3D)m_Point4D; }
            set
            {
                m_Point4D.X = value.X;
                m_Point4D.Y = value.Y;
                m_Point4D.Z = value.Z;
            }
        }

        #region zh-CHS Map属性 | en Public Properties

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 人物所在的地图
        /// </summary>
        private BaseMap m_BaseMap = null;
        #endregion
        /// <summary>
        /// 人物所在的地图
        /// </summary>
        public BaseMap Map
        {
            get { return m_BaseMap; }
            set
            {
                //BaseMap oldBaseMap = m_BaseMap;

                //EventHandler<BeforeUpdateMapEventArgs> tempBeforeEventArgs = m_ThreadEventBeforeUpdateMap;
                //if ( tempBeforeEventArgs != null )
                //{
                //    BeforeUpdateMapEventArgs eventArgs = new BeforeUpdateMapEventArgs( value, this );
                //    tempBeforeEventArgs( this, eventArgs );

                //    if ( eventArgs.IsCancel == true )
                //        return;
                //}

                //m_BaseMap = value;
                //m_BaseCreatureState.UpdateMap();

                //EventHandler<AfterUpdateMapEventArgs> tempAfterEventArgs = m_ThreadEventAfterUpdateMap;
                //if ( tempAfterEventArgs != null )
                //{
                //    AfterUpdateMapEventArgs eventArgs = new AfterUpdateMapEventArgs( oldBaseMap, this );
                //    tempAfterEventArgs( this, eventArgs );
                //}
            }
        }

        #endregion


        #region zh-CHS Deleted属性 | en Public Properties

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 人物是否删除
        /// </summary>
        private bool m_Deleted = false;
        #endregion
        /// <summary>
        /// BaseMobile是否已无效删除
        /// </summary>
        public bool Deleted
        {
            get { return m_Deleted; }
        }

        #region zh-CHS 人物的删除 | en
        /// <summary>
        /// 删除
        /// </summary>
        public void DeleteCreature()
        {
            //EventHandler<BaseCreatureEventArgs> tempBeforeEventArgs = m_ThreadEventBeforeDeleteCall;
            //if ( tempBeforeEventArgs != null )
            //{
            //    BaseCreatureEventArgs eventArgs = new BaseCreatureEventArgs( this );
            //    tempBeforeEventArgs( this, eventArgs );
            //}

            //m_Deleted = true;

            //EventHandler<BaseCreatureEventArgs> tempAfterEventArgs = m_ThreadEventAfterDeleteCall;
            //if ( tempAfterEventArgs != null )
            //{
            //    BaseCreatureEventArgs eventArgs = new BaseCreatureEventArgs( this );
            //    tempAfterEventArgs( this, eventArgs );
            //}
        }
        #endregion

        #endregion

        #region zh-CHS Saving属性 | en Public Properties

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private bool m_Saving = false;
        #endregion
        /// <summary>
        /// 是否正在存储数据中
        /// </summary>
        public bool Saving
        {
            get { return m_Saving; }
        }

        #region zh-CHS 共有方法 | en Public Methods
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockSave = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 保存人物的数据
        /// </summary>
        public void Save()
        {
            //// 移动物体的数据必须要成功才返回
            //ReaderWriterLockSlimEx.EnterWriteLock( m_LockSave );
            //{
            //    // 保存数据中......
            //    m_Saving = true;

            //    EventHandler<BaseCreatureEventArgs> tempEventArgs = m_ThreadEventCreatureSave;
            //    // 保存数据
            //    if ( tempEventArgs != null )
            //    {
            //        LOGs.WriteLine( LogMessageType.MSG_NOTICE, LanguageString.SingletonInstance.BaseCreatureString001, m_Name );

            //        BaseCreatureEventArgs eventArgs = new BaseCreatureEventArgs( this );
            //        tempEventArgs( this, eventArgs );

            //        LOGs.WriteLine( LogMessageType.MSG_NOTICE, LanguageString.SingletonInstance.BaseCreatureString002, m_Name );
            //    }

            //    // 保存数据结束......
            //    m_Saving = false;
            //}
            //ReaderWriterLockSlimEx.ExitWriteLock( m_LockSave );
        }
        #endregion

        #endregion

        #region zh-CHS BaseWorld属性 | en BaseWorld Properties

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 管理当前的世界服务
        /// </summary>
        private BaseWorld m_BaseWorld = null;
        #endregion
        /// <summary>
        /// 管理当前的世界服务
        /// </summary>
        public BaseWorld BaseWorld
        {
            get { return m_BaseWorld; }
            internal set { m_BaseWorld = value; }
        }

        #endregion

        #region zh-CHS MapSpaceNode属性 | en Public Properties

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private MapSpaceNode m_MapSpaceNode = null;
        #endregion
        /// <summary>
        /// 用于内部使用的地图点
        /// </summary>
        public MapSpaceNode MapSpaceNode
        {
            get { return m_MapSpaceNode; }
            internal set { m_MapSpaceNode = value; }
        }

        #endregion

        #region zh-CHS IArtificialIntelligence属性 | en Public Properties

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private IArtificialIntelligence m_ArtificialIntelligence = null;
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public IArtificialIntelligence AI
        {
            get { return m_ArtificialIntelligence; }
            set { m_ArtificialIntelligence = value; }
        }

        #endregion

        #region zh-CHS 接口实现 | en Interface Implementation

        /// <summary>
        /// 
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public int CompareTo( GameEntity1 other )
        {
            if ( other == null )
                return 1;

            return m_Serial.CompareTo( other.Serial );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public int CompareTo( object xObject )
        {
            return CompareTo( xObject as GameEntity1 );
        }

        #endregion
    }
}
#endregion
